package com.crm.manager.controller;

import com.crm.common.core.domain.AjaxResult;

import com.crm.manager.domain.Course;
import com.crm.manager.domain.dto.CourseDto;
import com.crm.manager.domain.dto.CoursePageQueryDto;
import com.crm.manager.domain.vo.PageVO;

import com.crm.manager.service.CourseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/clues/course")
@Slf4j
public class CourseController {


    @Autowired
    private CourseService courseService;


    /**
     * 新增
     * @param courseDto
     * @return
     */
    @PostMapping
    public AjaxResult add(@RequestBody CourseDto courseDto){
       log.info("新增:{}",courseDto);
       courseService.add(courseDto);
       return AjaxResult.success();
    }


//    /**
//     * 删除
//     * @param id
//     * @return
//     */
//    @DeleteMapping("/{id}")
//    public AjaxResult Delete(@PathVariable Long id){
//        log.info("删除:{}",id);
//        courseService.delete(id);
//        return AjaxResult.success();
//    }


    /**
     * 批量删除
     * @param
     * @return
     */
    @DeleteMapping("/{ids}")
    public AjaxResult deleteBatch(@PathVariable List<Integer> ids){
        courseService.deleteBatch(ids);
        return AjaxResult.success();

    }




    /**
     * 分页查询
     * @param coursePageQueryDto
     * @return
     */
    @GetMapping("/list")
    public PageVO pageQuery(CoursePageQueryDto coursePageQueryDto){
        log.info("分页查询");
        return courseService.pageQuery(coursePageQueryDto);
    }


    /**
     * 获取详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Long id){
        log.info("获取详情:{}",id);
        return AjaxResult.success(courseService.getInfo(id));
    }

    /**
     * 修改
     * @param
     * @return
     */
    @PutMapping
    public AjaxResult update(@RequestBody Course course){
        log.info("修改:{}",course);
        courseService.update(course);
        return AjaxResult.success();
    }



    /**
     * 获取课程列表
     * @param subject
     * @return
     */
    @GetMapping("/listselect")
    public AjaxResult listselect(String subject){
        List<Course> list = courseService.listselect(subject);
        return AjaxResult.success(list);
    }

//    @GetMapping("/listselect")
//    public AjaxResult listselect(){
//        List<Course> list = courseService.listselect(null);
//        return AjaxResult.success(list);
//    }



}













